<?php

namespace app\admin\controller;

use think\Controller;
use think\Db;

class  GoodsCheck extends Controller
{
  function index()
  {
    $nowSendM = json_decode(file_get_contents("php://input"));
    $nowid = $nowSendM->nowid;
    $result =  Db::table('gjc_goods')->where('gid', $nowid)->delete();
    return $result;
  }
  function getmsg()
  {
    $nowSendM = json_decode(file_get_contents("php://input"), true);
    // 模糊搜索是否有值
    if (!empty($nowSendM)) {
      $search = $nowSendM['secrchS'];
      $keyword = explode(" ", $search);
      $whereArry = [];
      foreach ($keyword as $value) {
        $whereArry[] = ['like', '%' . $value . '%'];
      }
      $whereArry[] = 'or';
    } else {
      $whereArry = ['like', '%%'];
    }
    $where['gid|g_name|g_sponsor'] = $whereArry;
    $result = Db::table('gjc_goods')
      ->alias('g')
      ->join('user u', 'u.uid = g.g_sponsor')
      ->where($where)
      ->order('g_create_time desc')
      ->select();
    return json($result);
  }
  function changesta()
  {
    $nowSendM = json_decode(file_get_contents("php://input"), true);
    $nowid = $nowSendM['nowid'];
    $result = Db::table('gjc_goods')->where('gid', $nowid)->update(['g_state' => '5']);
    return $result;
  }


  function getpending()
  {
    $nowSendM = json_decode(file_get_contents("php://input"), true);
    // 模糊搜索是否有值
    if (!empty($nowSendM)) {
      $search = $nowSendM['secrchS'];
      $keyword = explode(" ", $search);
      $whereArry = [];
      foreach ($keyword as $value) {
        $whereArry[] = ['like', '%' . $value . '%'];
      }
      $whereArry[] = 'or';
    } else {
      $whereArry = ['like', '%%'];
    }
    $where['gid|g_name|g_sponsor|g_text'] = $whereArry;
    $result = Db::table('gjc_goods')
      ->where($where)
      ->alias('g')
      ->join('user u', 'u.uid = g.g_sponsor')
      ->order('g_create_time desc')
      ->where('g_state', '1')
      ->select();
    return json($result);
  }

  function okchange()
  {
    $nowSendM = json_decode(file_get_contents("php://input"), true);
    $nowid = $nowSendM['nowid'];
    $result = Db::table('gjc_goods')->where('gid', $nowid)->update(['g_state' => '0'],['start_time'=>time()]);
    return json($result);
  }

  function notokchange()
  {
    $nowSendM = json_decode(file_get_contents("php://input"), true);
    $nowid = $nowSendM['nowid'];
    $result = Db::table('gjc_goods')->where('gid', $nowid)->update(['g_state' => '5']);
    return json($result);
  }

  function sendChangeMsg()
  {
    $nowSendM = json_decode(file_get_contents("php://input"), true);
    $nowMoney = $nowSendM['g_end_money'];
    $nowtext  = $nowSendM['g_text'];
    $nowname  = $nowSendM['g_name'];
    $nowid    = $nowSendM['gid'];
    $result   = Db::table('gjc_goods')->where('gid', $nowid)->update(
      [
        'g_end_money'  => $nowMoney,
        'g_text'       => $nowtext,
        'g_name'       => $nowname
      ]
    );
    if ($result == 1) {
      return res('success', '修改成功');
    } else {
      return res('primary', '您暂未修改任何内容');
    }
  }
}
